//
//  toupiaoresultViewController.m
//  hainingOASystem
//
//  Created by michael on 2017/12/12.
//  Copyright © 2017年 czd. All rights reserved.
//

#import "toupiaoresultViewController.h"
#import "toupiaoresultTableViewCell.h"
@interface toupiaoresultViewController ()

@end

@implementation toupiaoresultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"投票页面";
            self.view.backgroundColor = [UIColor whiteColor];
int testNum = 1;

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];

    formatter.numberStyle = kCFNumberFormatterRoundHalfDown;
    
    NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt: testNum]];

           [self makeUI];
[self requestadta];
    // Do any additional setup after loading the view.
}
- (void)requestadta{
 _id = @"7";
[MBProgressHUD showHUDAddedTo:self.view animated:YES];

 NSString *urlstring = [NSString stringWithFormat:@"%@%@",ktoupiaoresult,_id];
  [httpTool ZBPostNetDataWith:urlstring withDic:nil andSuccess:^(NSDictionary* dictionary){
  [MBProgressHUD hideHUDForView:self.view animated:YES];
_updic = dictionary[@"votePeriods"];
_array = dictionary[@"OptionInfoList"];


for (NSDictionary *dic in _array) {
    _num = _num +[dic[@"number"]intValue];
    NSLog(@"%ld",(long)_num);
}

[_tableview reloadData];

    }
 andFailure:^{
  [MBProgressHUD hideHUDForView:self.view animated:YES];

 }];

 }
- (void)makeUI{
_tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-kTopHeight-kTabBarHeight) style:UITableViewStylePlain];
_tableview.dataSource = self;
_tableview.delegate = self;
[self.view addSubview:_tableview];

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  _array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==0) {
 UITableViewCell* cell = [[UITableViewCell alloc]init];
 cell.selectionStyle = UITableViewCellSelectionStyleNone;
 UIImageView *image = [[UIImageView alloc]init];
NSString *url = [NSString stringWithFormat:@"%@%@",kip,_updic[@"imgUrl"]];
[image sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"加载"]];
image.frame = CGRectMake(0,0 , (KScreenWidth), 150);
       [cell.contentView addSubview:image];

return cell;
}else{

  static NSString *CellIdentifier = @"Celltpipiao";
NSDictionary *dic = _array[indexPath.row-1];
    toupiaoresultTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
        cell=[[toupiaoresultTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];

    formatter.numberStyle = kCFNumberFormatterRoundHalfDown;
    
    NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt: ( indexPath.row)]];
cell.Num = string;
cell.dic = dic;
cell.countnum = _num;
    return cell;



 }

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0){

return 150;
}else
{ NSString *string6 = @"一款简单的UILabel。支持修改字间距，行间距，设置关键字，下划线，自动计算宽高并返回";
        CGFloat titleSize6 = [OAToolBox sizebyText:string6 font:13 minsWidth:20];
//return titleSize6+20;
return 100+0;


}
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
